import time

from detect import start_to_identify
import os
i=1

def Time():
    return time.strftime("%Y-%m-%d %H:%M %S",time.localtime(time.time()))

def image():
    global i
    dirname = "test"
    time=Time()
    Parent_Directory='picture'
    dirname="./picture/" + time.split(' ')[0];

    print(type(dirname))
    picData = open(r'data\images\1.jpg', 'rb')
    picBytes = picData.read()
    arrBuf = bytearray(picBytes)
    # 创建名为test的文件夹

    if not os.path.exists(Parent_Directory):
        print("Given file path is not exist.")
        os.mkdir('picture')

    if not os.path.exists(dirname):
        print("Given file path is not exist.")
        os.mkdir(dirname)
    # 此处相当于文件路径 test/image.jpg，也就是在test文件夹中的image.jpg文件



    # 打开文件夹并写入图片
    filename = dirname + '/' + str(i) + '.jpg'

    with open(filename, 'wb') as f:
        f.write(arrBuf)
        f.close()
    i = i + 1

if __name__ == '__main__':
    # Image_location = 'data/images/1.jpg'
    # imgData = open(Image_location, mode='rb')
    # # start_to_identify(Image_location)
    # print(Image_location)
    # with open(r"D:\1.jpg", 'wb') as f:
    #     f.write(imgData)
    #     f.close()
    image()
    time.sleep(5)
    image()